package com.galen.chapter1.controller;

import com.galen.chapter1.entity.User;
import com.galen.chapter1.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author GalenGao
 * @version Id: UserControoler.java, v 0.1 2022/2/24 12:20 上午 GalenGao Exp $$
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class Chapter1UserController {

    private final UserService userService;


    @PostMapping("/saveUser")
    public ResponseEntity<User> saveUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.save(user));
    }


    @PostMapping("/findUserLike")
    public ResponseEntity<List<User>> findUser(@RequestBody User user) {
        return ResponseEntity.ok(userService.findUserLikeByName(user.getName()));
    }
}
